package org.bing.engine.console.helper {
    import mx.controls.dataGridClasses.DataGridColumn;

    import org.bing.flex.helper.StringHelper;

    public class LevelCodeFormatter {

        private static var block:String="00000000";

        public function format(item:Object, col:DataGridColumn):String {
            var code:String=item.code;
            var name:String=item.name;
            return " " + fill(code) + "> " + name;
        }

        private function fill(code:String):String {
            if (code == null || code.length != 40) {
                return "E" + code;
            }
            // remove free ends
            while (StringHelper.endWiths(code, block)) {
                code=code.substring(0, code.length - block.length);
            }
            var blank:int=code.length / block.length - 1;
            return fillFully(blank, "    ");
        }

        private function fillFully(len:int, bk:String):String {
            var s:String="";
            for (var i:int=0; i < len; i++) {
                s=s + bk;
            }
            return s;
        }

    }
}